from .base import BaseModel

class Domain(BaseModel):
    """域名模型"""
    
    def __init__(self):
        super().__init__()
        self.domain_id = None  # 域名ID
        self.domain = None  # 域名
        self.owner_id = None  # 所属单位ID
        self.owner_name = None  # 所属单位名称
        self.create_time = None  # 创建时间
        self.update_time = None  # 更新时间
    
    def __str__(self):
        return f"Domain(id={self.domain_id}, domain={self.domain}, owner={self.owner_name})"
    
    def to_dict(self):
        """将模型转换为字典格式"""
        return {
            'domain_id': self.domain_id,
            'domain': self.domain,
            'owner_id': self.owner_id,
            'owner_name': self.owner_name,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time else None,
            'update_time': self.update_time.strftime('%Y-%m-%d %H:%M:%S') if self.update_time else None
        }
    
    def is_valid(self):
        """验证域名格式是否有效"""
        # 简化版：检查是否包含至少一个点且不包含特殊字符
        if not self.domain:
            return False
        
        if '.' not in self.domain:
            return False
        
        if any(c in self.domain for c in ' /\\:*?"<>|'):
            return False
        
        return True